<template>
  <!-- 组件不需要渲染任何 DOM 元素 -->
    <div style="display: none;"></div>
</template>

<script setup>
import { onMounted } from 'vue';
import myAxios from "@/axios/axios.js";

const props = defineProps({
    articleId: {
        type: String,
        required: true
    }
});

onMounted(() => {
    trackArticleView();
});

const trackArticleView = async () => {
    try {
        const response = await myAxios.post(`/view/${props.articleId}`);
        console.log('View counted:', response.data.count);
    } catch (error) {
        console.error('Failed to track view:', error);
    }
};
</script>